package com.ryt.tuangou.controller;

import com.github.pagehelper.PageInfo;
import com.ryt.tuangou.pojo.PageUtil;
import com.ryt.tuangou.pojo.Product;
import com.ryt.tuangou.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description TODO
 * @Author ryt
 * @Date 2025/9/12 11:05
 */
@RestController
public class ProductController {
    @Autowired
    private ProductService productService;

    //添加商品
    @PostMapping("/addProduct")
    public Boolean addProduct(@RequestBody Product product){
        return productService.addProduct(product);
    }

    //分页查询
    @PostMapping("/getList")
    public PageInfo<Product> getList(@RequestBody PageUtil pageUtil){
        List<Product> list = productService.getList(pageUtil);
        return new PageInfo<>(list);
    }
    //删除商品
    @PostMapping("/removeProduct")
    public Boolean removeProduct(@RequestBody Product product){
        return productService.removeProduct(product);
    }


    //查询回显/根据id查询
    @PostMapping("/getPidByProduct")
    public Product getPidByProduct(@RequestBody Product product){
        return productService.getPidByProduct(product.getProductId());
    }
    //修改商品http://localhost:8080/updateProduct
    @PostMapping("/updateProduct")
    public Boolean updateProduct(@RequestBody Product product){
        product.setUpdateTime(LocalDateTime.now().toString());
        return productService.updateProduct(product);
    }


}
